package com.lc.tgxm.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lc.tgxm.R;
import com.lc.tgxm.model.HomeListmodel;
import com.zcx.helper.adapter.AppRecyclerAdapter;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

/**
 * HomeListAdapter 主页列表
 * Created by Lei on 2018/1/4.
 */
public abstract class HomeListAdapter extends AppRecyclerAdapter {

    public HomeListAdapter(Context context) {
        super(context);

        addItemHolder(HomeListmodel.class, CpVHolder.class);
    }

    public abstract void onItemClick(int position, HomeListmodel homeListmodel);

    public static class CpVHolder extends ViewHolder<HomeListmodel> {
        @BoundView(R.id.rl_itemroot)
        private View vRoot;
        @BoundView(R.id.iv_left)
        private ImageView ivleft;
        @BoundView(R.id.tv_title)
        private TextView tvtitle;
        @BoundView(R.id.tv_source)
        private TextView tvsource;
        @BoundView(R.id.tv_eye)
        private TextView tveye;


        public CpVHolder(AppRecyclerAdapter adapter, Context context, View view) {
            super(adapter, context, view);
        }

        @Override
        public int resourceId() {
            return R.layout.item_homelist;
        }

        @Override
        public void load(final int i, final HomeListmodel homeListmodel) {
            tvtitle.setText(homeListmodel.title);
            tvsource.setText(homeListmodel.source);
            tveye.setText(homeListmodel.eye);
            vRoot.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ((HomeListAdapter) adapter).onItemClick(i, homeListmodel);
                }
            });

            GlideLoader.getInstance().get(homeListmodel.picurl, ivleft);

//            int height = new Random().nextInt(100) + 200;
//            Log.w("HomeListAdapter", "homeListmodel.rHeight", homeListmodel.rHeight);
            ScaleScreenHelperFactory.getInstance().loadViewWidthHeight(vRoot, 0, homeListmodel.rHeight);
//            RelativeLayout.LayoutParams layoutParams=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)
        }

    }

}